From 349f04a5df6a911baa8c2f241ebcc37811562f4b Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Thu, 13 Oct 2005 08:38:49 +0100 Subject: [PATCH] NS_PER_TICK must be a s64 quantity. It is compared with possibly -ve values which we do not want to 'promote' to big +ve values. Signed-off-by: Keir Fraser --- linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c b/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c index ea09ebbb95..1157270955 100644 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c @@ -122,7 +122,8 @@ static u32 shadow_tv_version; static u64 processed_system_time; /* System time (ns) at last processing. */ static DEFINE_PER_CPU(u64, processed_system_time); -#define NS_PER_TICK (1000000000ULL/HZ) +/* Must be signed, as it's compared with s64 quantities which can be -ve. */ +#define NS_PER_TICK (1000000000LL/HZ) static inline void __normalize_time(time_t *sec, s64 *nsec) { @@ -235,9 +236,9 @@ static void __update_wallclock(time_t sec, long nsec) /* Adjust wall-clock time base based on wall_jiffies ticks. */ wc_nsec = processed_system_time; - wc_nsec += (u64)sec * 1000000000ULL; - wc_nsec += (u64)nsec; - wc_nsec -= (jiffies - wall_jiffies) * (u64)(NSEC_PER_SEC / HZ); + wc_nsec += sec * (u64)NSEC_PER_SEC; + wc_nsec += nsec; + wc_nsec -= (jiffies - wall_jiffies) * (u64)NS_PER_TICK; /* Split wallclock base into seconds and nanoseconds. */ tmp = wc_nsec; @@ -437,7 +438,7 @@ int do_settimeofday(struct timespec *tv) * be stale, so we can retry with fresh ones. */ for ( ; ; ) { - nsec = (s64)tv->tv_nsec - (s64)get_nsec_offset(shadow); + nsec = tv->tv_nsec - get_nsec_offset(shadow); if (time_values_up_to_date(cpu)) break; get_time_values_from_xen(); @@ -558,7 +559,7 @@ irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) } while (!time_values_up_to_date(cpu)); - if (unlikely(delta < (s64)-1000000) || unlikely(delta_cpu < 0)) { + if (unlikely(delta < -1000000LL) || unlikely(delta_cpu < 0)) { printk("Timer ISR/%d: Time went backwards: " "delta=%lld cpu_delta=%lld shadow=%lld " "off=%lld processed=%lld cpu_processed=%lld\n", @@ -802,7 +803,7 @@ static inline u64 jiffies_to_st(unsigned long j) * but that's ok: we'll just end up with a shorter timeout. */ if (delta < 1) delta = 1; - st = processed_system_time + ((u64)delta * NS_PER_TICK); + st = processed_system_time + (delta * (u64)NS_PER_TICK); } while (read_seqretry(&xtime_lock, seq)); return st; -- 2.30.2